﻿@model Views_Goods

@{
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@{
    var viewModel = Model ?? new Views_Goods();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}
<form id="S_Form" action="@Url.Action("detailInfo", "product")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" style="width:50%">
                <h5>
                    @ViewBag.Title,当前物料编号：[@viewModel.goods_id]；修改物料信息之前请先将<font color="red">物料下架</font>，否则可能会出现修改参数时用户正在下单的现象。
                </h5>
                <input type="hidden" value="@viewModel.goods_id" name="views_Goods.goods_id" />
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">品牌<em>*</em></td>
            <td>
                <select id="brand_id" name="views_Goods.brand_id">
                    @{
                        dc = new Dictionary<string, string>();
                        dbcontext.ADZ_BrandMaster.Where(t => t.is_del == 0).ToList().ForEach(t =>
                        {
                            dc.Add(t.brand_id.ToString(), t.brand_name);
                        });
                    }
                    @HtmlPagerHelper.ShowSelectOpton(dc, viewModel.brand_id.ToString())
                </select>
            </td>

            <td class="tableleft">分类<em>*</em></td>
            <td>
                <select id="category_id" name="views_Goods.category_id">
                    @{
                        dc = new Dictionary<string, string>();
                        ADZ_GoodsCategoryBiz.Instance.GetParentSunList().ForEach(t =>
                        {
                            dc.Add(t.category_id.ToString(), t.category_name);
                        });
                    }
                    @HtmlPagerHelper.ShowSelectOpton(dc, viewModel.category_id.ToString())
                </select>&nbsp;
            </td>
        </tr>
        <tr id="Tr_AgainPwd">
            <td class="tableleft">供应商<em>*</em></td>
            <td>
                <select id="supplier_id" name="views_Goods.supplier_id">
                    @{
                        dc = new Dictionary<string, string>();
                        dbcontext.ADZ_SupplierMaster.Where(t => t.is_del == 0).ToList().ForEach(t =>
                        {
                            dc.Add(t.supplier_id.ToString(), t.supplier_name);
                        });
                    }
                    @HtmlPagerHelper.ShowSelectOpton(dc, viewModel.supplier_id.ToString())
                </select>&nbsp;
            </td>

            <td class="tableleft">板块<em>*</em></td>
            <td>
                @{
                    var labeldic = ReleaseBiz.GetLabelTypeNameDic();
                    foreach (var item in labeldic)
                    {
                        <input type="radio" name="views_Goods.label_type" style="vertical-align:middle; margin-bottom:6px;" value="@item.Key" @(viewModel.label_type == byte.Parse(item.Key) ? "checked" : "") />@item.Value
                    }
                }
                <info id="business_info">
                    <br />
                    @{
                        long business_id = 0;
                        if (viewModel.label_type == (int)LabelType.Jingjia)
                        {
                            var jingjia_goods = dbcontext.ADZ_GoodsJingjia.FirstOrDefault(t => t.goods_id == viewModel.goods_id);
                            if (jingjia_goods != null)
                            {
                                business_id = jingjia_goods.jingjia_id;
                            }

                            if (business_id > 0)
                            {
                                <info>
                                    竞价编号：@business_id <a href="/jingjia/add/@business_id">查看竞价</a>
                                </info>
                            }
                            else
                            {
                                <info class="red">还未加到竞价包中</info>
                            }

                        }
                        if (viewModel.label_type == (int)LabelType.Huodong)
                        {
                            var huodong_goods = dbcontext.ADZ_GoodsHuodong.FirstOrDefault(t => t.goods_id == viewModel.goods_id);
                            if (huodong_goods != null)
                            {
                                business_id = huodong_goods.huodong_id;
                            }

                            if (business_id > 0)
                            {
                                <info>
                                    活动编号：@business_id <a href="/huodong/add/@business_id">查看活动</a>
                                </info>
                            }
                            else
                            {
                                <info class="red">还未加到活动中</info>
                            }

                        }
                    }
                </info>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">料号<em>*</em></td>
            <td><input type="text" name="views_Goods.MPN" maxlength="50" value="@viewModel.MPN" /></td>
            <td class="tableleft">结束时间<em></em></td>

            <td>
                <input type="text" name="views_Goods.end_time" class="calendar calendar-time" maxlength="50" value="@viewModel.end_time.ToString(1)" />
            </td>
        </tr>
        <tr>
            <td class="tableleft">售卖单位<em>*</em></td>
            <td>
                <input type="radio" name="views_Goods.goods_unit" style="vertical-align:middle; margin-bottom:6px;" value="K" @(viewModel.goods_unit == "K" ? "checked" : "") />K
                <input type="radio" name="views_Goods.goods_unit" style="vertical-align:middle; margin-bottom:6px;" value="PCS" @(viewModel.goods_unit == "PCS" ? "checked" : "") />PCS
            </td>
            <td class="tableleft">DC号<em>*</em></td>
            <td><input type="text" name="views_Goods.DCN" maxlength="50" value="@viewModel.DCN" /></td>
        </tr>
        <tr>
            <td class="tableleft">库存数量<em>*</em></td>
            <td><input type="text" name="views_Goods.stock_amount" maxlength="50" value="@viewModel.stock_amount" /> <info class="goods_unit">@viewModel.goods_unit</info></td>

            <td class="tableleft">最小订购量<em></em></td>
            <td><input type="text" name="views_Goods.min_amount" maxlength="50" value="@viewModel.min_amount" /> <info class="goods_unit">@viewModel.goods_unit</info></td>
        </tr>
        <tr>
            <td class="tableleft">上传价格</td>
            <td>
                <input type="text" name="views_Goods.price" maxlength="50" value="@viewModel.price" />
                <input type="radio" name="views_Goods.currency_type" style="vertical-align:middle; margin-bottom:6px;" value="0" />人民币/<info class="goods_unit">@viewModel.goods_unit</info>
                <input type="radio" name="views_Goods.currency_type" style="vertical-align:middle; margin-bottom:6px;" value="1" />美金/<info class="goods_unit">@viewModel.goods_unit</info>
            </td>
            <td class="tableleft">是否含税</td>
            <td>
                <input type="radio" name="views_Goods.include_tax" style="vertical-align:middle; margin-bottom:6px;" value="0" />未含税
                <input type="radio" name="views_Goods.include_tax" style="vertical-align:middle; margin-bottom:6px;" value="1" />含税
            </td>
        </tr>
        <tr>
            <td class="tableleft">市场价格</td>
            <td><input type="text" name="views_Goods.market_price" maxlength="50" value="@viewModel.market_price" />（<info class="goods_unit">@viewModel.goods_unit</info>）</td>

            <td class="tableleft">普通会员可看</td>
            <td>
                <input type="radio" name="views_Goods.show_min_level" style="vertical-align:middle; margin-bottom:6px;" value="0" />可看
                <input type="radio" name="views_Goods.show_min_level" style="vertical-align:middle; margin-bottom:6px;" value="1" />不可看
            </td>
        </tr>
        <tr>
            <td class="tableleft">供货价</td>
            <td colspan="3">
                <input type="text" name="views_Goods.supply_price" maxlength="50" value="@viewModel.supply_price" /> （<info class="goods_unit">@viewModel.goods_unit</info>）
            </td>            
        </tr>
        <tr>
            <td class="tableleft">是否上架</td>
            <td>
                <input type="radio" name="views_Goods.is_withdraw" style="vertical-align:middle; margin-bottom:6px;" value="0" />上架
                <input type="radio" name="views_Goods.is_withdraw" style="vertical-align:middle; margin-bottom:6px;" value="1" />下架

            </td>

            <td class="tableleft">上架时间</td>
            <td>
                <info>@viewModel.with_up_time</info>
                @if (viewModel.is_withdraw == 1)
                {
                    <br />
                    <info>下架时间:@viewModel.with_down_time</info>
                }
            </td>
        </tr>
        <tr>
            <td class="tableleft">下架原因</td>
            <td>@viewModel.draw_down_reason</td>
            <td class="tableleft">商品描述</td>
            <td><textarea name="views_Goods.product_desc" style="width:80%;" maxlength="2500" cols="4">@viewModel.product_desc</textarea></td>
        </tr>
        <tr>
            <td class="tableleft">商品图片</td>
            <td colspan="3">
                @{
                    //构建默认对象
                    var imglist = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == viewModel.goods_id).OrderBy(t => t.sort_NO).ThenBy(t => t.seq_id).ToList();
                }
                @{Html.RenderPartial(Url.Content("~/Views/Common/Imgs.cshtml"), imglist);}
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <p><span id="spMsg"></span></p>
                <button type="submit" class="btn btn-primary">保存</button> &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>

        </tr>
    </table>
    <script>
        BUI.use('bui/overlay', function (overlay) {
            $(function () {
                //绑定信息
                switch ('@viewModel.goods_unit') {
                    case 'K':
                        $("input[name='views_Goods.goods_unit']").get(0).checked = true;
                        break;
                    case 'PCS':
                        $("input[name='views_Goods.goods_unit']").get(1).checked = true;
                        break;
                }
                switch ('@viewModel.currency_type') {
                    case '0':
                        $("input[name='views_Goods.currency_type']").get(0).checked = true;
                        break;
                    case '1':
                        $("input[name='views_Goods.currency_type']").get(1).checked = true;
                        break;
                }

                switch ('@viewModel.is_withdraw') {
                    case '0':
                        $("input[name='views_Goods.is_withdraw']").get(0).checked = true;
                        break;
                    case '1':
                        $("input[name='views_Goods.is_withdraw']").get(1).checked = true;
                        break;
                }
                switch ('@viewModel.show_min_level') {
                    case '0':
                        $("input[name='views_Goods.show_min_level']").get(0).checked = true;
                        break;
                    case '1':
                    default:
                        $("input[name='views_Goods.show_min_level']").get(1).checked = true;
                        break;

                }
                switch ('@viewModel.include_tax') {
                    case '0':
                        $("input[name='views_Goods.include_tax']").get(0).checked = true;
                        break;
                    case '1':
                        $("input[name='views_Goods.include_tax']").get(1).checked = true;
                        break;
                }

                var rules = {
                    'views_Goods.aDZ_GoodsIMG_index': { required: true },
                    'views_Goods.DCN': { required: true },
                    'views_Goods.stock_amount': { required: true, IsNumber: true },
                    'views_Goods.goods_unit': { required: true },
                    'views_Goods.label_type': { required: true },
                    'views_Goods.brand_name': { required: true },
                    'views_Goods.supplier_name': { required: true },
                    'views_Goods.MPN': { required: true },
                    'views_Goods.category_name': { required: true },
                    'views_Goods.min_amount': {  IsNumber: true },
                    'views_Goods.price': { IsNumber: true },
                    'views_Goods.market_price': { IsNumber: true },
                    'views_Goods.include_tax': { required: true },
                    'views_Goods.currency_type': { required: true },
                    'views_Goods.commission_rate': { IsNumber: true },
                    'first_img': { required: true }

                };
                var messages = {
                    //'aDZ_GoodsMaster.goods_unit': { required: '售卖单位必选' },
                };

                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: rules,
                    messages: messages,
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {

                            ShowActionResult(result, function () { self.location = document.referrer; });//self.location = document.referrer;
                        });
                    }
                });

            });
        });

        $("input[name='views_Goods.goods_unit']").click(function () {
            $(".goods_unit").html($(this).val());
        });

    </script>
</form>
